<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
	<meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="format-detection" content="telephone=no,email=no">
    <meta name="screen-orientation" content="portrait">
    <meta name="x5-orientation" content="portrait">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-title" content="积分明细">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <title>积分明细</title>
    <link rel="stylesheet" type="text/css" href="./../css/base.css?v=20170821001">
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/layer/3.0.1/mobile/layer.min.js"></script>
    <script src="https://cdn.bootcss.com/fastclick/1.0.6/fastclick.min.js"></script>
    <script src="./../js/common.js?v=20170814001"></script>
    <script src="./../js/conf.js?v=20170801001"></script>
    <script>
	$(function(){
		FastClick.attach(document.body);
		
		var params = _CZWeb.getUrlParams();
		var brandid = params["brandid"];
		
		var $detail = $('.data-box'),$loading = $('.loading');

		var pad = function pad(num, n) {  
		    var len = num.toString().length;
		    while(len < n) {
		        num = "0" + num;  
		        len++;  
		    }
		    return num;  
		};

		var showView = function(list){
			var html = "";
			$.each(list, function(index, val) {
				/*var d = new Date(this.ctime);
				var time = d.getFullYear()+'-'+pad((d.getMonth()+1),2)+'-'+pad(d.getDate(),2)+ ' '+ pad(d.getHours(),2) + ':'+pad(d.getMinutes(),2)+':'+pad(d.getSeconds(),2);*/
				var amount = this.amount>0?('+'+this.amount):(this.amount<0?(this.amount):0);
				html += '<div class="row flex flex-y-center">'+
					'<div class="flex-1">'+
						'<span class="title">'+this.src_name+'</span>'+
						'<br>'+
						'<span class="time">'+this.ctime+'</span>'+
					'</div>'+
					'<div class="jifen">'+amount+'</div>'+
				'</div>';
			});
			$detail.append(html);
		};

		var page = 1,size = 10,loading = false,scrollHeight = 0,over = false;

		var loadData = function(){
			var param = $.extend(true, {page:page++,size:size}, params);
			$.ajax({url: _detailPageInfoAction,type: 'POST',dataType: 'json',data: param})
			.done(function(data) {
				if(data&&data.result==0){
					if(data.integral_logs&&data.integral_logs.length>0){
						showView(data.integral_logs);
						scrollHeight = $('.data-box').height() - $(window).height();//加载完数据 刷新滚动条高度
						if(data.integral_logs.length<param.size){
							over = true;
							if (param.page===1) {
								$loading.addClass('hidden');
							}else{
								$loading.html('没有更多了!');
							}
						}
					}else{
						over = true;
						if (param.page===1) {
							$loading.html('暂无积分记录!');
						}else{
							$loading.html('没有更多了!');
						}
						// layer.msg('所有数据已经加载完成!');
					}
				}else{
					layer.msg((data&&data.reason)||'系统错误!');
				}
			})
			.fail(function() {
				layer.msg('请求服务器失败!');
			}).always(function() {
				loading = false;
			});
		};

		var init = function(){
			//绑定下拉加载更多
			$(window).scroll(function(e) {
	            var scrollTop = $(window).scrollTop();
				if(scrollHeight<=scrollTop&&loading===false&&over===false){
					loading = true;
					loadData();
				}
	        });
	        loadData();//开始加载数据
		};

		init();
	});

	</script>
</head>
<body>
	<div class="page page-detail">
		<div class="data-box"></div>
		<div class="loading">正在加载...</div>
	</div>
	<script>
	var _hmt = _hmt || [];
	(function() {
	  var hm = document.createElement("script");
	  hm.src = "//hm.baidu.com/hm.js?9b40deeaa9ce094daadf13e0dc1a4729";
	  var s = document.getElementsByTagName("script")[0];
	  s.parentNode.insertBefore(hm, s);
	})();
	</script>
</body>
</html>